<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
<style type="text/css">
ul {
	background-color: #e2e2e2;
	list-style: none;
}
.lps {
	background-color: #929292;
	
}

</style>
</head>
<body>
	<h2>文章列表</h2>
	<hr>
	
	<c:forEach items="${list}" var="art">
		<ul>
			<li>${art.title}</li>
			<li>${art.content}</li>
			<li>作者:${art.dname}</li>
			<li>发布时间:${art.created}</li>
		</ul>
		<input type="button" value="编辑" onclick="toUpdate(${art.id},${page })">
		<input type="button" value="删除" onclick="toDelete(${art.id},${page })">
		<hr>
	</c:forEach>
	
	
	<c:if test="${page>1 }">
		<input type="button" value="上一页" onclick="SelectPage(${page-1});">
	</c:if>
	
	
	<a href="articleFindByPage.do">首页</a>
	
	<c:forEach begin="1" end="${maxPage}" var="i">
		<c:choose>
			<c:when test="${i==page}">
				<span class="lps">
					<a href="articleFindByPage.do?page=${i}">${i}</a>
				</span>
			</c:when>
			<c:otherwise>
				<a href="articleFindByPage.do?page=${i}">${i}</a>
			</c:otherwise>
		</c:choose>
	</c:forEach>
	

	当前第${page }页/共${maxPage }页
	<select id="sel" onchange="selPage();">
	
	<c:forEach begin="1" end="${maxPage}" var="i">
		<c:choose>
			<c:when test="${i==maxPage}">
				<option value="${i}" selected="selected">${i}</option>
			</c:when>
			<c:otherwise>
				<option value="${i}">${i}</option>
			</c:otherwise>
		</c:choose>	
	</c:forEach>

	</select>
	<a href="articleFindByPage.do?page=${maxPage}">末页</a>
	
	
	<c:if test="${page<maxPage}">
		<input type="button" value="下一页" onclick="SelectPage(${page+1});">
	</c:if>

	
</body>
<script type="text/javascript">
function toDelete(id,page) {
	var isDelete = window.confirm("确定删除吗？");
	if(isDelete){
		window.location.href = "articleDelete.do?id="+id+"&page="+page;
	}
}
function toUpdate(id,page) {
	window.location.href = "articleFindById.do?id="+id+"&page="+page;
}
// 跳转到上下页数
function SelectPage(page) {
	window.location.href = "articleFindByPage.do?page="+page;
	
}
function selPage() {
	var page = sel.value;
	window.location.href = "articleFindByPage.do?page="+page;
}
</script>
</html>